﻿#ifndef DISPOSEWIDGET_H
#define DISPOSEWIDGET_H

#include <QStandardItemModel>
#include <QWidget>
#include "audioplaythread.h"

namespace Ui {
class DisposeWidget;
}

class DisposeWidget : public QWidget
{
    Q_OBJECT

public:
    explicit DisposeWidget(QString filePath,QWidget *parent = nullptr);
    ~DisposeWidget();

    QString getAudioFilePath() const;
    void setWavParam();
signals:
    void signal_makeSpectrogram(int viewWidth,uint64_t startIndex,uint64_t stopIndex);
public slots:
    void slot_playIndex(uint64_t index);
    void slot_playState(bool state);

    void slot_changeSelectState(bool b);
    void slot_changeSelectRange(double selectMinX,double selectMaxX);

    void slot_editSelectRow();
    void slot_delSelectRow();
    void slot_clearTableModel();

    void slot_refMarkBand();
private slots:
    void on_playBtn_clicked();
    void on_playBandBtn_clicked();
    void on_saveBtn_clicked();
    void on_tableView_customContextMenuRequested(const QPoint &pos);
    void on_saveToTable_clicked();
    void on_addToTable_clicked();

    void on_playTime_valueChanged(int value);

    void on_loopPlay_clicked(bool checked);

    void on_setWavParamBtn_clicked();

    void on_languageBox_currentIndexChanged(const QString &arg1);

private:
    Ui::DisposeWidget *ui;
    QString audioFilePath;//语音文件路径
    //文件相关信息
    bool existsWavHeader;//存在wav头
    uint64_t fileHeaderSize;//文件头大小
    uint64_t fileDataSize;//文件数据大小
    uint32_t sampleRate;//采样率
    uint16_t channleNumber;//通道数量
    uint16_t bitsPerSample;//采样位数

    bool playing;//播放状态
    uint64_t playNowIndex;//播放当前位置
    AudioPlayThread audioPlayThread;//播放线程

    bool selectState;
    double selectBegin;
    double selectEnd;

    QStandardItemModel *tableModel;

    QMap<QString,QString> languageMap;
private:
    void readJson();
    void writeJson();
};

#endif // DISPOSEWIDGET_H
